/***********************************************************************
** Copyright (C) 2011 Anthony Naddeo <anthony.naddeo@gmail.com>
**
** This file is part of LinkedUp
**
** LinkedUp is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** LinkedUp is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this package; If not, see <http://www.gnu.org/licenses/>.
**
***********************************************************************/
import QtQuick 1.1
import com.meego 1.0
import "../components"

MyPage {
	id: root

	width: parent.width; height: parent.height
	title: "Job"

	tools: ToolBarLayout {
		ToolIcon { platformIconId: "toolbar-view-menu";
			anchors.right: parent===undefined ? undefined : parent.right
			onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
		}
		ToolIcon { platformIconId: "toolbar-back";
			anchors.left: parent===undefined ? undefined : parent.left
			visible: pageStack ? pageStack.depth > 1 ? true : false : false
			onClicked: {
				if(pageStack.depth > 1)
					pageStack.pop()
			}
		}
		ToolIcon {
			id: star
			property bool marked: User.bookmarked(profileID)
			anchors.horizontalCenter: parent.horizontalCenter
			platformIconId: marked ? "toolbar-favorite-mark" : "toolbar-favorite-unmark"
			/*uncomment the following when they implement DELETE method*/
//			onClicked: marked ? httpDelete(API.delete_job_bookmark(profileID)) : post(API.post_company_follow(profileID))
			onClicked: marked ? Qt.openUrlExternally(model.get(0).jobUrl) : post(API.post_job_bookmark(profileID))
		}


	}

	onProfileIDChanged: get(API.get_job_by_id(profileID))
	onGetFinished: {
		model.xml = responseText
	}
	onPostFinished: {
		if(statusCode === "201"){
			star.marked = true
			User.bookmark(profileID,model.get(0).name) //add the company id to the QHash
		}
	}


	property string profileID


	JobModel{
		id: model
		onStatusChanged: {
			if(status === XmlListModel.Ready && xml){
				root.title = get(0).name
			}
		}
	}

	ListView{
		id: general
		anchors.fill: parent
		anchors.topMargin: borderHeight+10
		anchors.leftMargin: 10
		anchors.rightMargin: 10

		model: model
		delegate: JobDelegate{}
	}

//	Component{
//		id: content
//		Flickable{
//			anchors.fill: parent
//			contentHeight: column.height + 50

//			Column{
//				id: column
//				anchors.top: parent.top
//				width: parent.width
//				spacing: 20





//				ListView{
//					id: general
//					width: parent.width
//					height: contentHeight
//					model: companyModel
//					interactive: false
//					delegate: JobDelegate{
//						id: compDel
//						onBookmark: root.post(API.post_job_bookmark(id))
//						onUnbookmark: root.httpDelete(API.delete_job_bookmark(id))
////						onFinance: {
////							var comp = Qt.createComponent("../Finance.qml")
////							var obj = comp.createObject(root.parent)
////							obj.ticker = ticker
////							obj.caller = root
////							root.state = "hidden"
////						}
//						onNews: {
//							var comp = Qt.createComponent("News.qml")
//							var obj = comp.createObject(root.parent)
//							obj.searchString = name
//							obj.caller = root
//							root.state = "hidden"
//						}

//						Connections{
//							target: root
//							onPostFinished: {
//								var x = xml
//								var sCode = statusCode
//								var sText = statusText
//								if(sCode === "201"){
//									compDel.bookmarked = true
//									User.bookmark(id,name) //add the job id to the QHash
//								}
//							}
//							onDeleteFinished:{
//								var x = xml
//								var sCode = statusCode
//								var sText = statusText
//								if(sCode === "201"){
//									compDel.bookmarked = false
//									User.unbookmark(id) //remove the job id from the QHash
//								}
//							}
//						}
//					}
//				}



////				Section{
////					id: specialties
////					text: "Specialties"
////					width: column.width
////					model: SpecialtiesModel{xml: profileXML}
////					delegate: SpecialtiesDelegate{}
////				}

////				Section{
////					id: locations
////					text: "Locations"
////					width: column.width
////					listSpacing: 20
////					model: LocationsModel{xml: profileXML}
////					delegate: LocationsDelegate{}

////				}
//			}


//		}

//	}







}
